@extends('layouts.app')

@section('title', translate('收货地址'))
@section('content')
@include('common.header', ['title'=> translate('收货地址')])
<link rel="stylesheet" href="/fontpage/css/cart_check.css">
<link rel="stylesheet" href="/fontpage/css/animate.css">
<script src="/fontpage/js/iscroll.js"></script>
<script src="/fontpage/js/small.function.js"></script>
<script src="/fontpage/js/modal.js"></script>
<script type="text/javascript">
        $(function () {
            $(".returntop").click(function () {
                $('body,html').animate({scrollTop: 0}, 1000);
            });
            var height = document.getElementById("container").offsetHeight;
            if (height <= 568) {
                $("#minHeight").addClass('minHeight');
                $(".returntop").hide();
            }
        });
    </script>
<div class="container" id="container">
    <div class="wrapper">
        <div id="minHeight" class="minHeight">

            <!-- 选择收货地址 -->
            <div class="common-wrapper">
                <div class="animation">

                    <!-- 选项卡1 -->
                    <div class="tab1" id="addressList">
                            @foreach($pageList as $row)
                                <div class="step3 border-1px step3-adress">
                                    <div class="s-item">
                                        <div class="sitem-l mr10" data-id="{{$row->id}}" style="width:100%;border-bottom: 1px solid rgba(0,0,0,.07)">
                                            <!-- 地址状态 -->
                                            @if($row->is_default==1)
                                                <span class="default-icon address_default"></span>
                                            @endif

                                            <p class="cellName" style="width:95%">{{$row->name}} {{$row->mobile}}</p>
                                            <p class="cellAddress" style="width:95%">{{$row->address}} / {{$row->code}}</p>
                                        </div>
                                        <div class="sitem-m">

                                                <div class="f_choose fl
                                                @if($row->is_default==1)
                                                f_choose_selected
                                                @endif
                                                " aid="{{$row->id}}" onclick="toDefault('{{$row->id}}',1,0)"

                                                data-checked="true"

                                                >
                                                    <b></b>
                                                    <label>{{translate("设为默认")}}</label>
                                                </div>



                                            <div class="f_bottom fr">
                                                <a class="btn_edit" href="/user/toAddressDetail?id={{$row->id}}&jp={{request()->get('jp',0)}}&type={{request()->get('type',0)}}">{{translate("修改")}}</a>
                                                <a class="btn_del" href="javascript:;" onclick="deleteAddress('{{$row->id}}', 1)">{{translate("删除")}}</a>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                                <div style="height: 0.5em;"></div>
                            @endforeach

                    </div>
                    <!-- End 选项卡1 -->
                </div>
                <!-- 新建站点 -->

                <div class="add-address tab1" style="z-index:9999">
                    <a class="add-btn" href="/user/toAddressDetail?jp={{request()->get('jp',0)}}&type={{request()->get('type',0)}}">
                        + {{translate("新建收货地址")}}
                    </a>
                </div>
                <!-- End 新建地址 -->
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {

		@if($type == 1)
			$('.sitem-l').click(function(){
    			var id = $(this).attr('data-id');
    			var url = '/user/cartCommit?jp={{request()->get("jp",0)}}&address='+id;
    			var form = $('<form>{{ csrf_field() }}</form>');
                form.attr('action', url);
                form.attr('method', 'post');
                form.attr('target', '_self');

                var input1 = $("<input type='hidden' name='json' />");
                input1.attr('value', "{{session('_session_carts')}}");
                form.append(input1);

                var input2 = $("<input type='hidden' name='type' />");
                input2.attr('value', 1);
                form.append(input2);

                form.appendTo("body");
                form.css('display', 'none');
                form.submit();
			})
		@endif
    });

    var todefault = 0;

    /**
     * 设为默认
     */
    function toDefault(id, type, isdefalut) {
        if (todefault == 1) {
            return;
        }
        todefault = 1;
		ajaxurl('',{id:id, type:'default'},function(res){
			layer.msg(res.msg)
			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
				window.location.reload();//页面刷新
			},2000);
		})
    }

    var todelete = 0;

    /**
     * 删除地址
     */
    function deleteAddress(id, type) {
        if (todelete == 1) {
            return;
        }
        todelete = 1;
        if (!confirm('{{translate("确认删除？")}}')) {
            todelete = 0;
            return;
        }
        ajaxurl('',{id: id, type:'del'},function(data){
        	if (data.status == 1) {
                $.prompt('{{translate("删除成功")}}', {
                    buttons: {'{{translate("确定")}}': true}
                });
                window.location.reload();
            } else {
                $.prompt('{{translate("删除失败")}}', {
                    buttons: {'{{translate("确定")}}': true}
                });
            }
        })


    }

</script>
@endsection
@section('footer')
     @include('common.footer')
@stop
